yjx.directive('endAppear', ['$rootScope', '$timeout', function endAppear($rootScope, $timeout) {
    /**底部加载判断块是否在屏幕可见区*/
    return {
        restrict: "EAC",
        scope: false,
        link: function ($scope, $element, attr) {
            // angular.element(document.querySelector('.scrollable-content')).scrollTop = 2000;
            $scope.hideShows = true;
            var top = parseInt(attr.appearTop ? attr.appearTop : 5);
            $scope.$watch(attr.endAppear, function (newVals) {
                $timeout(function () {
                    $scope._winheight = angular.element(window).height();
                    if ($scope._winsroll < 0) {
                        $scope._winsroll = 0;
                    } else {
                        $scope._winsroll = angular.element(window).scrollTop();
                    }
                    //$rootScope._winsroll = angular.element(window).scrollTop();
                    $scope.top = $element.offset().top;
                    //console.info($scope.top <($scope._winsroll+$scope._winheight) )
                    //console.info($scope.top);
                    //console.info($scope._winsroll);
                    //console.info($scope._winheight)
                    //console.info("_update"+$scope._updated+$scope.paging+ "+" +$scope.paging.pages + "+" + $scope.pageNum+"hideshows"+$scope.hideShows)
                    if ($scope.paging && ($scope.paging.pages > $scope.pageNum)) {
                        if ($scope.hideShows) {
                            $timeout(function () {
                                //限制翻页进度

                                if ($scope.top < ($scope._winsroll + $scope._winheight) && $scope._updated == false) {
                                    $scope.hideShow = '显示';
                                    //开始倒计时
                                    $timeout.cancel($scope.loadTimer);
                                    $scope.loadTimer = $timeout(function () {
                                        $scope.hideShow = '加载数据中';
                                        //滑动到底部触发事件
                                        $scope.hideShows = false;
                                        $scope.$parent.pageNum++;
                                        $scope.list();
                                        //加页码
                                        $timeout.cancel($scope.loadTimer);
                                    });
                                    $timeout.cancel($scope.loadTimer2);
                                    $scope.loadTimer2 = $timeout(function () {
                                        $scope.hideShows = false;
                                        $scope._updated = false;
                                        $timeout.cancel($scope.loadTimer2);
                                    })
                                } else {
                                    $scope._updated = false;
                                    $timeout.cancel($scope.loadTimer);
                                    $timeout.cancel($scope.loadTimer2);
                                    $timeout.cancel($scope.loadTimer3);
                                }
                            });
                        } else {
                            $scope.hideShow = '隐藏'
                            $timeout.cancel($scope.loadTimer3);
                            $timeout.cancel($scope.loadTimer);
                            $scope.loadTimer3 = $timeout(function () {
                                //限制翻页进度
                                //alert($scope._updated )
                                $scope._updated = !$scope._updated;
                                $scope.hideShows = true;
                                //alert($scope._updated )
                                $timeout.cancel($scope.loadTimer3);
                            })
                        }
                    } else {
                        if ($scope.paging) { //最开始不能初始化paging对象
                            $scope._updated = 'nomore';
                            if($scope.nomore){
                                $scope.nomore();
                            }
                        }
                    }
                })
            });
        }
    }
}])